<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<%@include file="../common/include-header.jsp" %>
<link rel="stylesheet" href="/static/layui/css/layui.css" media="all"/>
<link rel="stylesheet" href="/static/css/bootstrapValidator.min.css" media="all"/>
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.js"></script>
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap-paginator.js"></script>
<body>
<style>
    .emailCode {
        position: absolute;
        right: 0px;
        top: 1px;
        height: 32px;
        width: 80px;
        background: #00a1d6;
        color: white;
        border: 1px solid #00a1d6;;
    }

    .emailCode:hover {
        background: rgba(0, 161, 214, 0.8);
    }
</style>
<div class="form-content">
    <form id="frmUpdate" class="layui-form changePwd">
        <div class="layui-divStyle">
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block form-group">
                    <input type="password" name="password" placeholder="请输入新密码" lay-verify="required|newPwd" id="newPwd"
                           class="layui-input pwd">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block form-group">
                    <input type="password" name="confirmPwd" placeholder="请确认密码" lay-verify="required|confirmPwd"
                           class="layui-input pwd">
                </div>
            </div>
            <div class="layui-form-item form-group" style="position:relative">
                <label class="layui-form-label">验证码</label>
                <div class="layui-input-block">
                    <input id="yzm" class="layui-input" name="emailCode" placeholder="请输入验证码"
                           lay-verify="required"
                           type="text" maxlength="50">
                    <button onclick="getCode()" type="button" class="emailCode"><span>点击获取</span></button>
                </div>
            </div>
            <div class="layui-form-item form-group">
                <div class="layui-input-block">
                    <input class="layui-btn" id="submit1" type="button" value="立即修改" lay-submit=""
                           lay-filter="changePwd"></input>
                    <button id="reset" type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
</div>

<%--<%@include file="../common/include-footer.jsp" %>--%>
<script>
    $(function () {
        layui.use('layer', function () {
        });

        // $("#closeTab").click(function () {
        //     var menu = window.sessionStorage.getItem("menu");
        //     var jsonMenu = JSON.parse(menu);
        //     for (var i = 0; i < jsonMenu.length; i++) {
        //         if (jsonMenu[i].title == $("#title").val()) {
        //             window.deleteTab(jsonMenu[i].layId);
        //         }
        //     }
        // $(menu).each(function () {
        //     alert(JSON.parse(this[0]))
        //     // if (JSON.parse(this).title == ){
        //     //
        //     // }
        // });
        // });

        // var prefix = "/system/user";
        //
        // function submitHandler() {
        //     var data = $("#form-user-update").serializeArray();
        //     var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
        //     $.operate.savePut(prefix + "/update", data);
        // }
    });

    $('#frmUpdate').on("click", "#submit1", function () {
        var name = $("input[name=name]").val();
        var password = $("input[name=password]").val();
        var identityId = $("input[name=identityId]").val();
        $.ajax({
            url: "changePwd",
            data: {"name": "${user.name}", "password": "${user.password}", "identityId": "${user.identityId}"},
            type: "post",
            dataType: "json",
            success: function (msg) {
                if (msg.success) {
                    layer.msg("密码修改成功！请您重新登入", {time: 3000}, function () {
                        parent.location.href = "showLogin";
                    });
                } else {
                    layer.msg("修改失败,原因是" + msg.errorMsg, {time: 2000});
                }
            }
        });
    });

    $('#frmUpdate').bootstrapValidator({
        //统一配置使用的图标
        feedbackIcons: {},
        trigger: "blur",
        fields: {
            password: {
                validators: {
                    notEmpty: {message: '密码不得为空！'},
                    stringLength: {
                        min: 6,
                        max: 18,
                        message: '密码必须大于6小于18'
                    }
                }
            },
            confirmPwd: {
                validators: {
                    notEmpty: {message: '二次密码不得为空！'},
                    identical: {
                        field: "password",
                        message: '两次输入密码不一致'
                    }
                }
            },
            emailCode: {
                validators: {
                    notEmpty: {message: '验证码不得为空！'},
                    remote: {
                        type: "post",
                        url: "email/checkEmailCode",
                        message: "验证码错误或以失效"
                    }
                }
            }
        }
    });

    $('#reset').click(function () {
        $('#frmUpdate')[0].reset();
    });

    var prefix = "/system/user";

    function submitHandler() {
        var data = $("#form-user-update").serializeArray();
        var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
        $.operate.savePut(prefix + "/update", data);
    }

    function getCode() {

        $.ajax({
            type: "GET",
            url: "email/sendEmail?receiveMailAccount=${user.email}",
            success: function (msg) {
                if (msg.success) {
                    layer.msg("验证码已发送请注意接收", {time: 2000})
                } else {
                    layer.msg("邮件发送失败，原因是：" + msg.errorMsg, {time: 2000, skin: "errorMsg"})
                }
            }
        });
    }
</script>
</body>
</html>
